﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.IO;

namespace Intorise.MiniDB.ClassLibrary
{
    internal class Helper
    {
        static DirectoryInfo rootDir = null;
        static DirectoryInfo dataRootDir = null;
        static int objectSize = 5;

        static Helper()
        {
            string root = ConfigurationManager.AppSettings["DatabaseRoot"];
            if (string.IsNullOrEmpty(root))
            {
                root = "";
            }

            if (!Directory.Exists(root))
            {
                root = AppDomain.CurrentDomain.BaseDirectory + "\\" + root;
            }

            rootDir = new DirectoryInfo(root);
            dataRootDir = new DirectoryInfo(root + "\\Data");
            if (!dataRootDir.Exists)
            {
                dataRootDir.Create();
            }
            Log.Write(AppDomain.CurrentDomain.FriendlyName + " MiniDatabase is started.");
        }

        public static DirectoryInfo RootDir
        {
            get { return Helper.rootDir; }
        }

        public static DirectoryInfo DataRootDir
        {
            get { return Helper.dataRootDir; }
        }

        public static int ObjectSize
        {
            get { return Helper.objectSize; }
        }

        ~Helper()
        {
            Log.Write(AppDomain.CurrentDomain.FriendlyName + " MiniDatabase is stoped.");
        }
    }
}
